package com.lzy.cloud.ticket.train.facade;

import com.lzy.cloud.ticket.train.constant.LMMApi;
import com.lzy.cloud.ticket.train.constant.LMMContant;
import com.lzy.cloud.ticket.train.request.BaseRequest;
import com.lzy.cloud.ticket.train.request.InsuranceOrderRequest;
import com.lzy.cloud.ticket.train.request.InsuranceRequest;
import com.lzy.cloud.ticket.train.request.app.InsuranceAppRequest;
import com.lzy.cloud.ticket.train.request.app.InsuranceOrderAppRequest;
import com.lzy.cloud.ticket.train.response.InsuranceOrderResponse;
import com.lzy.cloud.ticket.train.response.InsuranceResponse;
import com.lzy.cloud.ticket.train.util.BasePushUtil;
import com.lzy.framework.core.utils.DozerUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Component
@Slf4j
public class InsuranceFacade {

    @Resource
    private RestTemplate restTemplate;

    @Autowired
    private BasePushUtil basePushUtil;

    public InsuranceResponse queryInsurance(){
        InsuranceAppRequest insuranceAppRequest = new InsuranceAppRequest();
        insuranceAppRequest.setProduct(LMMContant.INSURANCE_PRODUCT);
        BaseRequest baseRequest = basePushUtil.push(LMMContant.APP_KEY,"","","");
        InsuranceRequest insuranceRequest = DozerUtils.map(baseRequest,InsuranceRequest.class);
        insuranceRequest.setData(insuranceAppRequest);
        InsuranceResponse insuranceResponse = restTemplate.postForObject(LMMApi.INSURANCE_URL,insuranceRequest,InsuranceResponse.class);
        return insuranceResponse;
    }

    public InsuranceOrderResponse queryInsuranceOrder(InsuranceOrderAppRequest insuranceOrderAppRequest){
        BaseRequest baseRequest = basePushUtil.push(LMMContant.APP_KEY,LMMContant.INSURANCE_ORDER_METHOD,LMMContant.MESSAGE_FORMT,"");
        InsuranceOrderRequest insuranceOrderRequest = DozerUtils.map(baseRequest,InsuranceOrderRequest.class);
        insuranceOrderRequest.setData(insuranceOrderAppRequest);
        InsuranceOrderResponse insuranceOrderResponse = restTemplate.postForObject(LMMApi.INSURANCE_ORDER_URL,insuranceOrderRequest,InsuranceOrderResponse.class);
        return insuranceOrderResponse;
    }
}
